package vo;

import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

import po.CollegePO;


public class CollegeListVO {
	private List<CollegePO> collegeList;

	public CollegeListVO(List<CollegePO> collegeList) {
		super();
		this.collegeList = collegeList;
	}
	public List<CollegePO> getCollegeList() {
		return collegeList;
	}
	public String getCollegeName(String collegeID) throws NoSuchElementException{
		CollegePO college = getCollege(collegeID);
		if(college == null){
			throw new NoSuchElementException();
		}
		return college.getCollegeName();
	}
	public String getCollegeID(String collegeName){
		for( CollegePO college : collegeList){
			if(college.getCollegeName().equals(collegeName)){
				return college.getCollegeID();
			}
		}
		throw new  NoSuchElementException();
	}
	public List<String> getCollegeNames(){
		LinkedList<String> list = new LinkedList<String>();
		for(CollegePO college : collegeList){
			list.add(college.getCollegeName());
		}
		return list;
	}
	private CollegePO getCollege(String collegeID){
		for(CollegePO c : collegeList){
			if(c.getCollegeID().equals(collegeID)){
				return c;
			}
		}
		return null;
	}
	@Override
	public String toString() {
		return "CollegeListVO [collegeList=" + collegeList + "]";
	}
	public String[][] toDyadicArray(){
		String[][] array = null;
		int i=0;
		for(CollegePO c : collegeList){
			array[i][0] = c.getCollegeID();
			array[i][1] = c.getCollegeName();
			i++;
		}
		return array;
	}
	
}
